package com.tg.app.helper;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.tg.appcommon.android.TGLog;

import org.w3c.dom.Text;

/**
 * 记录画中画设备当前的画面通道
 */
public class MultiPlayerHelper {

    private static final String TAG = "MultiPlayerHelper";

    public static final int UNREAD_VALUE = -100;

    public static final int NOT_SELECTED_BEFORE_VALUE = -1;

    private static final String SP_FILE_NAME = "TAN_GE_MULTI_PLAYER_CHANNEL_CONFIG";

    public static int readChannel(Context context, String uuid) {
        if (context == null || TextUtils.isEmpty(uuid)) {
            return 0;
        }

        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
        int selectedChannel= sharedPreferences.getInt(uuid, NOT_SELECTED_BEFORE_VALUE);
        TGLog.i(TAG, "[readChannel] uuid = " + uuid + " , channel = " + selectedChannel);
        return selectedChannel;
    }

    public static void writeChannel(Context context, String uuid, int channel) {
        if (context == null || TextUtils.isEmpty(uuid)) {
            return;
        }

        TGLog.i(TAG, "[writeChannel] uuid = " + uuid + " , channel = " + channel);

        SharedPreferences sharedPreferences = context.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(uuid, channel);
        editor.apply();
    }

}
